package com.tnl.app.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tnl.app.dao.PersonDAO;
import com.tnl.app.dao.TbFileDAO;
import com.tnl.app.entity.Person;
import com.tnl.app.entity.PersonRecom;
import com.tnl.app.entity.TbFile;
import com.tnl.app.service.IPersonService;

@Service
public class PersonService implements IPersonService {
	@Autowired
	private PersonDAO personDAO;
	@Autowired
	private TbFileDAO tbFileDAO;

	@Override
	public Person getPersonByID(Integer personId) {
		int id = personId.intValue();

		return personDAO.getById(id);
	}

	@Override
	public List<Person> getAllPersons() {
		return personDAO.getALL();
	}

	@Override
	public int createPerson(Person person) {
		return personDAO.save(person);
	}

	@Override
	public void deleteById(Integer personId) {
		personDAO.delete(personId.toString());
	}

	@Override
	public void updatePerson(Person person) {
		personDAO.update(person);
	}

	@Override
	public void createPersonRecom(PersonRecom person){
		personDAO.savePersonRecom(person);
	}
	
	public PersonRecom getByPersonRecomPhone(String phone){
		return personDAO.getByPersonRecomPhone(phone);
	}
	
	public int savePersonRecom(PersonRecom person){
		return personDAO.savePersonRecom(person);
	}
	
	public PersonRecom getByPersonRecomId(int personId){
		return personDAO.getByPersonRecomId(personId);
	}
	
	public long getCountDocByPersonId(Integer personId) {
		return tbFileDAO.getCountDocByPersonId(personId);
	}
	
	public TbFile getByDocId(String docId) {
		return tbFileDAO.getByDocId(docId);
	}
	
	public int saveFile(TbFile tbFile) {
		return tbFileDAO.save(tbFile);
	}

}
